import cv2
filename = r'F:\lenna.png'
sourceimg = cv2.imread(filename)
grayimg = cv2.cvtColor(sourceimg,cv2.COLOR_BGR2GRAY)
#均值滤波
average = cv2.blur(grayimg,(5,5),0)
cv2.imshow("average",average)
#高斯平滑
gauss = cv2.GaussianBlur(grayimg,(5,5),0)
cv2.imshow("gaussian",gauss)
#中值滤波
medianblurimg = cv2.medianBlur(grayimg,5) ####################
cv2.imshow("medianblurimg",medianblurimg)
#开闭运算
#kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(3,3))         #定义矩形结构元素
#open_morphologyimg = cv2.morphologyEx(grayimg,cv2.MORPH_OPEN,kernel,iterations=1)  ##################膨胀#########
#close_morphologyimg = cv2.morphologyEx(grayimg,cv2.MORPH_CLOSE,kernel,iterations=1)  ##################腐蚀#########
#cv2.imshow("open_morphologyimg",open_morphologyimg)
#cv2.imshow("close_morphologyimg",close_morphologyimg)
cv2.waitKey(0)